<?
	session_start();
	include_once 'functionsHR.php';
	include_once 'functions_db.php';
	include 'headermenu.php';
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
   <link rel="stylesheet" href="yui.css" type="text/css">
<head>
	<title>Methodology Portal</title>

</head>
<body>
<?php   
     //modificare: prin if-ul de mai jos se verifica daca s-a realizat logarea; deasemenea acesta trebuie sa apara in fiecare pagina
	if(ISSET($_SESSION["userId"]) == FALSE)
    {
         echo "<script type =\"text/javascript\">window.location.href=\"methodology.php\";</script>";
		 
		 exit();
	}  
?>
<div id="dhtmltooltip"></div>
<script type="text/javascript">
/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip
</script>

<div id="doc" class="yui-t7">
   
   <div id="bd" role="main">
   
   <div class="yui-gc">
    <div class="yui-u first">
	<!-- YOUR DATA GOES HERE -->
    <form action="" name="testQR" method="post" >
	<div align="right">  <input type="submit" name="add" value="Add person" align="right"> </div>
	</form>
	    </div>
    <div class="yui-u">
	<!-- YOUR DATA GOES HERE -->
	    </div>
 </div>
   
	<div class="yui-gc">
    <div class="yui-u first">
	<!-- YOUR DATA GOES HERE -->


	<?
	$dbh=dbConn();
	//####FUNCTII:
	//####se pare ca daca pun functiile inainte se da refresh la pagina singura!!! si cred ca stiu de ce!
	//####STERGE PROIECT:
	if(isset($_POST['qr_del']))
	{
		//echo ("Proiectul identificat cu numarul ".$_GET[rowid]." a fost sters.");
		mysql_query("delete from human_resources where id = ".$_GET[rowid].";") or die(mysql_error());
			unset($_GET[rowid]);
		//refreshPage('http://localhost/methodology/');
	}

	{
	//####ADAUGA persoana:
	if(isset($_POST['qr_add']))
		if($_POST['pname'] != null) 
		{
			//echo ("A fost adaugat un nou proiect.");
			
			//$fileName = $_FILES['cv']['name'];
			$fileName = $_FILES['cv']['name'];
            $tmpName  = $_FILES['cv']['tmp_name'];
			$fileSize = $_FILES['cv']['size'];
			
			if($fileSize > 0)
			{
			move_uploaded_file($tmpName, 'cvs/'.$fileName);
			$filePath = "cvs/" . $_FILES['cv']['name'];
			
			$result2 = returnQuery("select * from companies where name = '".$_POST['id_company']."';",''); 
			$row2 = mysql_fetch_assoc($result2);
			
			mysql_query("INSERT INTO human_resources (id, name, surname, id_company, position, address, mobile_ph, company_ph, experience, cv, work_schedule,account)
			VALUES (NULL,'".$_POST['pname']."', '".$_POST['surname']."', '".$row2[id]."', '".$_POST['position']."', '".$_POST['address']."', '".$_POST['mobile_ph']."', '".$_POST['company_ph']."', '".$_POST['experience']."', '$filePath', '".$_POST['work_schedule']."', '".$_SESSION["account"]."');") or die(mysql_error());  
			unset($_GET[rowid]);
			//refreshPage('http://localhost/methodology/');
			}
			
			else
			
			{
			$result2 = returnQuery("select * from companies where name = '".$_POST['id_company']."';",''); 
			$row2 = mysql_fetch_assoc($result2);
			
			mysql_query("INSERT INTO human_resources (id, name, surname, id_company, position, address, mobile_ph, company_ph, experience, cv, work_schedule,account)
			VALUES (NULL,'".$_POST['pname']."', '".$_POST['surname']."', '".$row2[id]."', '".$_POST['position']."', '".$_POST['address']."', '".$_POST['mobile_ph']."', '".$_POST['company_ph']."', '".$_POST['experience']."', NULL , '".$_POST['work_schedule']."', '".$_SESSION["account"]."');") or die(mysql_error());  
			unset($_GET[rowid]);
			//refreshPage('http://localhost/methodology/');
			}
		}
	}

	//####MODIFICA PROIECT:
	if(isset($_POST['qr_update']))
	{
		$fileName = $_FILES['cv']['name'];
        $tmpName  = $_FILES['cv']['tmp_name'];
		$fileSize = $_FILES['cv']['size'];
		
		$result2 = returnQuery("select * from companies where name = '".$_POST['id_company']."';",''); 
	    $row2 = mysql_fetch_assoc($result2);
		
		if($fileSize > 0)
		{
		move_uploaded_file($tmpName, 'cvs/'.$fileName);
		$filePath = "cvs/" . $_FILES['cv']['name'];
			
		//echo ("Proiectul identificat cu numarul ".$_GET[rowid]." a fost modificat.");
		$sql = "UPDATE `ec_methodology`.`human_resources` SET `name` = '".$_POST['pname']."', `id_company` = '".$row2[id]."', `position` = '".$_POST['position']."', `address` = '".$_POST['address']."', `mobile_ph` = '".$_POST['mobile_ph']."', `company_ph` = '".$_POST['company_ph']."', `experience` = '".$_POST['experience']."', `cv` = '$filePath', `work_schedule` = '".$_POST['work_schedule']."' WHERE `human_resources`.`id` = ".$_GET[rowid].";";
		}
		
		else
		{
		//echo ("Proiectul identificat cu numarul ".$_GET[rowid]." a fost modificat.");
		$sql = "UPDATE `ec_methodology`.`human_resources` SET `name` = '".$_POST['pname']."', `id_company` = '".$row2[id]."', `position` = '".$_POST['position']."', `address` = '".$_POST['address']."', `mobile_ph` = '".$_POST['mobile_ph']."', `company_ph` = '".$_POST['company_ph']."', `experience` = '".$_POST['experience']."', `work_schedule` = '".$_POST['work_schedule']."' WHERE `human_resources`.`id` = ".$_GET[rowid].";";
		}
		
		mysql_query($sql) or die(mysql_error());  
		unset($_GET[rowid]);
		//refreshPage('http://localhost/methodology/');
	}




	$result = returnQuery("Select * from human_resources where account=".$_SESSION["account"].";",$dbh);
	
	//####afisam inregistrarile in tabela:
	while ($row = mysql_fetch_assoc($result)) 
	{
		
	$result2 = returnQuery("select * from companies where id = ".$row['id_company'].";",''); 
	$row2 = mysql_fetch_assoc($result2);
	
	///////////
	echo "<div class='yui-u'>";
	echo "<table border='1'>";
	
  echo "<tr><td colspan='2' bgcolor=#00AFF2><a onMouseover=\"ddrivetip('Click on person\'s name to edit details')\";
 onMouseout=\"hideddrivetip()\">Name: </a><a href='human_res.php?rowid=".$row["id"]."'>".$row["name"]." ".$row["surname"]." </a></td></tr>";
  echo "<tr><td width='110'>Company: </td><td>".$row2["name"]."</td></tr>";
  echo "<tr><td width='110'>Position: </td><td>".$row["position"]."</td></tr>";
  echo "<tr><td width='110'>Address: </td><td>".$row["address"]."</td></tr>";
  echo "<tr><td width='110'>Mobile phone:</td><td>".$row["mobile_ph"]."</td></tr>";
  echo "<tr><td width='110'>Company phone:</td><td>".$row["company_ph"]."</td></tr>";
  echo "<tr><td width='110'>Experience: </td><td>".$row['experience']."</td></tr>";
  if ($row['cv']!= NULL)
  {echo "<tr><td width='110'>CV: </td><td> <a href='downloadcv.php?id=".$row['id']."'> ".$row['cv']." </a> </td></tr>";}
  
    echo "</table>";
	echo "<br>";
	   echo " </div>";

    /////////
	}
	
	echo('</table>');
	mysql_free_result($result);	
	?>
 
<br>
 
     </div>
    <div class="yui-u">
 <!-- AL DOILEA ECRAN!!! -->
 	<?

	
	
		//####afisam sectiunea add/update/delete:
	if(isset($_POST['add'])) 
	{
		unset($_GET[rowid]);
		display($_GET[0]);
	}
	
	//####Functie pentru selectarea unui proiect:
	if (isset($_GET[rowid])!=0)
	{
		
		display($_GET[rowid]);
	}
	
	//####Functie pt butonul Anulare:
	if(isset($_POST['qr_cancel'])) 
	{
			unset($_GET[rowid]);
		//unset($_POST);
	refreshPage('http://localhost/methodology/human_res.php');
	}
	
	//####Inchidem sesiunea DB:
	dbClose($dbh);
	?>

 
<br>
     </div>
</div>
 

	</div>
   
</div>

</body>
</html>
<? include 'footer.php'; ?>